package models

import (
	"errmsg"
	"github.com/astaxie/beego/logs"
	"github.com/astaxie/beego/orm"
)

// 使用模式任务列表
type UseModeTasks struct {
	Id        string `orm:"column(id);pk" json:"id" form:"id"`
	After     int    `orm:"column(after)" json:"after" form:"after"`
	Sta       string `orm:"column(sta)" json:"sta" form:"sta"`
	State     int    `orm:"column(state)" json:"state" form:"state"`
	Order     int    `orm:"column(order)" json:"order" form:"order"`
	Name      string `orm:"column(name)" json:"name" form:"name"`
	UseModeId string `orm:"column(use_mode_id)" json:"-" form:"use_mode_id"`
}

func init() {
	orm.RegisterModel(new(UseModeTasks))
}

func (m *UseModeTasks) TableName() string {
	return "use_mode_tasks"
}

func GetUseModeTaskByUmid(umid string) ([]*UseModeTasks, error) {
	var (
		ls  []*UseModeTasks
		err error
		num int64
	)

	sql := "select * from use_mode_tasks where use_mode_id = ? order by `order` asc"
	if num, err = orm.NewOrm().Raw(sql, umid).QueryRows(&ls); err != nil {
		logs.Error("GetUseModeTaskByUmid error:", err)
		return nil, errmsg.ErrResponseSystem
	}
	if num == 0 {
		return nil, nil
	}

	return ls, nil
}
